1144A - Diverse Strings - CodeForces Solution


implementation strings *800

Please click on ads to support us..

Python Code:

n = int(input())
for i in range(n):
    s = input()
    print('YES' if ord(max(s)) - ord(min(s)) == len(s)-1 and len(set(s)) == len(s) else 'NO')
	  	 					 			 	 	 	 		   			

C++ Code:

#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main()
{
    bool f=0;
    
    cin>>n;
    while (n--){
        cin>>s;          
     sort(s.begin(),s.end());
      if(s.size()==1)f=1;
      else{
         for(int i=0;i<s.size()-1;i++){
         if(s[i+1]==s[i]+1) f=1;
         else {
             f=0;
             break;
         }
     
     }  
      }

     if(f)cout<<"Yes\n";
     else cout<<"No\n";
     f=0; 
   }
     

    return 0;

}


Comments

Submit
0 Comments
More Questions

676B - Pyramid of Glasses
597A - Divisibility
1632A - ABC
1619D - New Year's Problem
242B - Big Segment
938A - Word Correction
159C - String Manipulation 10
258A - Little Elephant and Bits
1536C - Diluc and Kaeya
1428C - ABBB
1557A - Ezzat and Two Subsequences
255A - Greg's Workout
1059A - Cashier
1389C - Good String
1561A - Simply Strange Sort
1337B - Kana and Dragon Quest game
137C - History
1443C - The Delivery Dilemma
6C - Alice Bob and Chocolate
1077C - Good Array
285B - Find Marble
6A - Triangle
1729A - Two Elevators
1729B - Decode String
1729C - Jumping on Tiles
1729E - Guess the Cycle Size
553B - Kyoya and Permutation
1729D - Friends and the Restaurant
1606C - Banknotes
580C - Kefa and Park